package com.hzhq.contract.convert;

import com.hzhq.contract.bean.dto.AttachmentDTO;
import com.hzhq.contract.bean.entity.Attachment;
import com.hzhq.contract.bean.vo.AttachmentVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

/**
 * @author: hzhq1255
 * @mail: hzhq1255@163.com
 * @date: 2021/4/20 21:27
 * @desc:
 */
@Mapper
public interface AttachmentConvertBasic {

    AttachmentConvertBasic INSTANCE = Mappers.getMapper(AttachmentConvertBasic.class);

    @Mappings({
            @Mapping(target = "attachId", expression = "java(com.hzhq.contract.util.ConvertUtil.objectIdToString(source.getAttachId()))"),
            @Mapping(target = "contractId", expression = "java(com.hzhq.contract.util.ConvertUtil.objectIdToString(source.getContractId()))")
    })
    AttachmentDTO poToDto(Attachment source);

    @Mappings(value = {
            @Mapping(target = "attachId", expression = "java(com.hzhq.contract.util.ConvertUtil.stringToObjectId(source.getAttachId()))"),
            @Mapping(target = "contractId", expression = "java(com.hzhq.contract.util.ConvertUtil.stringToObjectId(source.getContractId()))")
    })
    Attachment dtoToPo(AttachmentDTO source);


    @Mappings({
            @Mapping(target = "sizeString",expression = "java(com.hzhq.contract.convert.method.AttachmentConvertMethod.fileSizeToString(source.getSize()))"),
            @Mapping(target = "attachType",expression = "java(com.hzhq.contract.convert.method.AttachmentConvertMethod.getAttachTypeByAttachName(source.getAttachName()))")
    })
    AttachmentVO dtoToVO(AttachmentDTO source);



    AttachmentDTO voToDto(AttachmentVO source);
}
